package lj.jdbcPool.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import lj.jdbcPool.util.JDBCUtils;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author lj
 * @Description:
 * @date 2020-11-24 12:20
 * @QQ 851477108
 */


public class druidDemo2 {
    public static void main(String[] args) throws Exception {
        /*
         * 完成查询操作：给account表查询一条记录
         */
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            //1.获取连接
            conn = JDBCUtils.getConnection();
            //2.定义sql
            String sql = "select * from account where id = ?";
            //3.获取pstmt对象
            ps = conn.prepareStatement(sql);
            //4.给？赋值
            ps.setInt(1,1);
            //5.执行sql
            ResultSet rs = ps.executeQuery();
            //6.1游标向下移动一行
            rs.next();
            //6.3获取数据
            String name = rs.getString("name");
            double balance = rs.getDouble(3);
            System.out.println(name+"-"+balance);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //6. 释放资源
            JDBCUtils.close(ps,conn);
        }
    }
}
